package com.itheima.commons;

import lombok.Data;

import java.io.Serializable;

/**
 * 结果返回类
 *
 * @author DogeGuo
 */
@Data
public class R<T> implements Serializable {
    private static final long serialVersionUID = 288559L;

    private Integer code;
    private String message;
    private T data;

    public R(Integer code, String string, T data) {
        this.code = code;
        this.message = string;
        this.data = data;
    }

    public R(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static<T> R<T> ok(Object data) {
        return new R(Code.SUCCESS, "操作成功", data);
    }

    public static<T> R<T> err(String msg) {
        return new R(Code.BAD_REQUEST, msg);
    }
}
